package com.rabbit.producer.controller;

import com.rabbit.producer.dto.NewCoffeeRequest;
import com.rabbit.producer.mq.MqMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author 超
 * Create by fengc on  2022/9/29 23:11
 * 消息发送
 * 生产者
 */
@RestController
@RequestMapping("/producer")
@Slf4j
public class ProducerController {

    @Resource
    MqMessage message;

    @PostMapping("/sendCoffee")
    public String sendCoffee(@RequestBody NewCoffeeRequest coffeeRequest) {
        log.info("将要推送的消息={}",coffeeRequest.toString());
        boolean isFlag = message.sendCoffee().send(MessageBuilder.withPayload(coffeeRequest).build());
        if (isFlag) {
            return "消息推送成功!";
        }
        return "消息推送失败";
    }
}
